<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #app {
            box-sizing: border-box;
            padding: 10px;
        }

        #app .title {
            line-height: 50px;
            font-size: 24px;
            text-align: center;
        }

        #app .text {
            display: flex;
            align-items: center;
            justify-content: space-around;
            padding: 10px;
            margin-bottom: 10px;
        }

        #app .text input {
            height: 30px;
            width: 80%;
            border-radius: 10px;
            padding-left: 10px;
            border: 1px solid #ccc;
        }

        #app .history {
            line-height: 50px;
            font-size: 24px;
            margin-left: 20px;
            font-size: 18px;
        }

        #app .list {
            margin: 10px 20px;
        }

        #app .list .item {
            display: inline-block;
            margin: 5px;
        }

        #app .list .item .content {
            color: rgb(113, 112, 112);
            background-color: aquamarine;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="title">搜索</div>
        <div class="text">
            <input type="text" placeholder="搜索商家，商品名称" v-model="inputText">
            <span class="search" @click="search">搜索</span>
        </div>
        <div class="history">历史搜索</div>
        <div class="list">
            <div class="item" v-for="(item,index) in tasklist" :key="index">
                <span class="content">{{item.name}}</span>
            </div>
        </div>
    </div>
</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v = new Vue({
        el: '#app',
        data: {
            inputText: '',//保存输入框中的值
            tasklist: [
                /*{name:天天鲜} */
            ]
        },
        methods: {
            search() {
                if (this.inputText) { //输入框不为空, 才添加任务
                    //构造一个任务对象
                    var obj = { name: this.inputText };
                    //将任务对象 添加到任务列表中
                    this.tasklist.push(obj);
                    //清空输入框
                    this.inputText = '';
                }
            }
        }
    })
</script>